import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';

import * as COS from 'cos-nodejs-sdk-v5';
import { OssService } from './oss.service';
import { OssController } from './oss.controller';
import { FileRecord } from './entities/file-record.entity';

@Module({
  imports: [TypeOrmModule.forFeature([FileRecord], 'mysql')],
  providers: [
    OssService,
    {
      provide: 'COS_CLIENT',
      useFactory: (configService: ConfigService) => {
        return new COS({
          SecretId: configService.get('tencent.oss.SecretId'),
          SecretKey: configService.get('tencent.oss.SecretKey'),
        });
      },
      inject: [ConfigService],
    },
  ],
  controllers: [OssController],
  exports: [OssService],
})
export class OssModule { }
